<%@page import="study.itwill.team5.admin.AdminItem"%>
<%@page import="study.itwill.jsp.WebHandler"%>
<%@page import="study.itwill.team5.board.Comment"%>
<%@page import="study.itwill.common.PatternChecker"%>
<%@page import="study.itwill.common.DBHandler"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ page trimDirectiveWhitespaces="true"%>
<%@ include file="../session.jsp"%>
<%@ include file="../dbcon.jsp"%>
<%
	PatternChecker checker = PatternChecker.getInstance();

	// 모든 파라미터 받기
	int comment_seq = web.getInt("comment_seq");
	int board_seq = web.getInt("board_seq");
	int member_seq = web.getInt("member_seq");
	String comment = web.getValue("comment");
	
	if (comment_seq == -1) {
		db.disconnect();
		web.goPage(null, "파라미터가 잘못되었습니다.");
		return;
	}
	
	if (board_seq == -1) {
		db.disconnect();
		web.goPage(null, "파라미터가 잘못되었습니다.");
		return;
	}
	
	if (member_seq == -1) {
		db.disconnect();
		web.goPage(null, "파라미터가 잘못되었습니다.");
		return;
	}
	
	if (!checker.isValue(comment)) {
		db.disconnect();
		web.goPage(null, "파라미터가 잘못되었습니다.");
		return;
	}
	comment = comment.replace("\n", "<br />");
%>
<%
	/** 데이터 저장 */
	Comment com = new Comment();
	boolean result = com.editComment(comment_seq, comment, board_seq, member_seq);
	
	/** 접속 해제 */
	db.disconnect();
	
	if (!result) {
		web.goPage(null, "수정에 실패했습니다.");
		return;
	}
%>
<script>
	self.window.alert("덧글을 수정하였습니다.");
	opener.location.reload();
	window.close();
</script>